<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/15
 * Time: 11:40
 */

namespace Admin\Controller;

use Think\Controller;
use Think\Verify;

class AdminLoginController extends Controller
{
    /**
     * 获取用户ID，用户跳转
    **/
    public function adminLoginSkip()
    {
        $a_id=session('a_id');
        if (empty($a_id)) {
            $this->display('index/login');
        } else {
            $getAdminCategory=D('AdminLogin')->getAdminCategory($a_id);
            $getLibraryInfo=D('Library')->getLibraryInfo();
            $this->assign('_getLibraryInfo', $getLibraryInfo);
            $this->assign('_getAdminCategory', $getAdminCategory);
            //            $adminName=getAdminName();
            //            $this->assign('_adminName',$adminName);
            $this->display('Public/common');
        }
    }
    /**
     * 用户验证
    **/
    public function adminVerify()
    {
        $a_email=I('a_email');
        $a_pwd=I('a_pwd');
        $code = I('verify');
        if (empty($a_email)||empty($a_pwd)) {
            $this->error('信息不能为空!');
        }
        if (!$this->checkVerify($code)) {
            $this->error('验证码错误!');
        }
        $email=D('AdminAdd')->getAdminEmail($a_email);
        if ($email==false) {
            $this->error('用户邮箱不存在，请重新输入！');
        }
        $adminStatus=D('AdminLogin')->getAdminInfo($a_email);
        if (empty($adminStatus)) {
            $this->error('您的账号已被禁用，请及时联系系统管理员！');
        }
        $res=D('AdminLogin')->adminLoginSkip($a_email, $a_pwd);
        if ($res==false) {
            $this->error('密码错误，请重新登录！');
        } else {
            $this->success('管理员登录成功！', U('Admin/AdminLogin/adminLoginSkip'));
        }
    }
    /* 验证码 */
    public function verify()
    {
        $verify = new Verify();
        $verify->fontSize = 30;
        $verify->length   = 4;
        $verify->useNoise = false;
        $verify->entry();
    }
    /* 检查验证码 */
    private function checkVerify($code)
    {
        $verify = new Verify();
        return $verify->check($code);
    }
}
